package com.aduerr.v1shouyin.mvp.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.aduerr.v1shouyin.R;
import com.aduerr.v1shouyin.common.Constants;

public class CardUseSuccessActivity extends AppCompatActivity {

    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.rl_title)
    RelativeLayout rlTitle;
    @BindView(R.id.iv_paysuccess)
    ImageView ivPaysuccess;
    @BindView(R.id.tv_member_name)
    TextView tvMemberName;
    @BindView(R.id.tv_cardname)
    TextView tvCardname;
    @BindView(R.id.tv_hexiao_time)
    TextView tvHexiaoTime;
    @BindView(R.id.tv_confim)
    TextView tvConfim;
    private String paymoney;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_card_use_success);
        ButterKnife.bind(this);
        initDate();
    }

    private void initDate() {
        tvTitle.setText("核销结果");
        Intent intent = getIntent();
        intent.getStringExtra("memberNo");
        String member = intent.getStringExtra("member");
        String uTime = intent.getStringExtra("uTime");
        intent.getStringExtra("biztype");
        intent.getStringExtra("touse");
        paymoney = intent.getStringExtra("paymoney");
        String title = intent.getStringExtra("title");
        tvMemberName.setText(member);
        tvCardname.setText(title);
        tvHexiaoTime.setText(uTime);
    }

    @OnClick({R.id.img_back, R.id.tv_confim})
    public void onViewClicked(View view) {
        switch(view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.tv_confim:
                if(paymoney != null) {
                    toShowDialog();
                } else {
                    finish();
                }
                break;
        }
    }

    private void toShowDialog() {
        new AlertDialog.Builder(this).setCancelable(false)
                .setMessage("您还需要支付" + paymoney + "元")
                .setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        Intent intent = new Intent(CardUseSuccessActivity.this,
                                ScanningActivity.class);
                        intent.putExtra(Constants.QRCODE_CAPUTER,
                                Constants.SCANCODECOLLECTION_QR);
                        intent.putExtra("cardshaoma", "1");
                        intent.putExtra(Constants.REALMONEY, paymoney);
                        startActivity(intent);
                        finish();
                    }
                }).create().show();
    }


}
